﻿Public Class AdminmenuV2
    Dim users As New Users
    Dim customers As New Customers
    Dim incidents As New Incidents
    Dim beschrijvingen As New Collection
    Private Sub AdminmenuV2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Divider.BackColor = System.Drawing.ColorTranslator.FromHtml("#ff4e4e")
        GebruikersListView.Hide()
        KlantenListView.Hide()
        IncidentenListView.Show()
        Weergave_CB.Show()
        weergavezoekenLabel.Show()
        Opties_Menu_Header.Text = "Incidenten"
        If incidents.LoadAllFromDB() = "True" Then
            Weergave_CB.SelectedIndex = 0
        End If
        Me.Size = Me.MinimumSize
    End Sub

    Private Sub GebruikersListView_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles GebruikersListView.MouseDoubleClick
        If GebruikersListView.SelectedItems.Count.ToString >= 1 Then
            Bewerkgebruiker.weergeefGebruiker(GebruikersListView.SelectedItems.Item(0).SubItems.Item(3).Text.ToString) 'Het OVnummer wordt doorgegeven naar Bewerkgebruiker
        End If
    End Sub


    Private Sub GebruikersListView_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles GebruikersListView.Resize
        Dim MeSize = Me.Size
        Gebruikernaam.Width = ((MeSize.Width / 4) + (Gebruikeruid.Width))
        GebruikerKlas.Width = ((MeSize.Width / 10))
        Gebruikerovnummer.Width = ((MeSize.Width / 5))
        Gebruikerlevel.Width = (MeSize.Width / 10)
        Gebruikerdisabled.Width = ((MeSize.Width / 4) - (Gebruikeruid.Width * 2.2))
    End Sub

    Private Sub KlantenListView_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles KlantenListView.MouseDoubleClick
        If KlantenListView.SelectedItems.Count.ToString >= 1 Then
            Bewerkklant.weergeefKlant(KlantenListView.SelectedItems.Item(0).SubItems.Item(0).Text.ToString) 'Het id wordt doorgegeven naar Bewerkklant
        End If
    End Sub

    Private Sub KlantenListView_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles KlantenListView.Resize
        Dim MeSize = Me.Size
        klantvoorletter.Width = ((MeSize.Width / 10))
        klantachternaam.Width = ((MeSize.Width / 5))
        klantovnummer.Width = ((MeSize.Width / 5))
        klantemail.Width = ((MeSize.Width / 5))
        klanttelefoon.Width = ((MeSize.Width / 5) - (klantid.Width))
    End Sub

    Private Sub IncidentenListView_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles IncidentenListView.MouseDoubleClick
        If IncidentenListView.SelectedItems.Count.ToString >= 1 Then
            Bewerkincident.weergeefIncident(IncidentenListView.SelectedItems.Item(0).SubItems.Item(0).Text.ToString)
        End If
    End Sub

    Private Sub incidentenlistview_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles IncidentenListView.Resize, KlantenListView.Resize
        Dim MeSize = Me.Size
        incidentovnummer.Width = ((MeSize.Width / 4) - ((incidentid.Width + incidentapparaat.Width)))
        incidentcategorie.Width = ((MeSize.Width / 3) - ((incidentid.Width + incidentstatus.Width + incidentapparaat.Width) / 2))
        incidentbehandelaar.Width = ((MeSize.Width / 3) - ((incidentid.Width + incidentstatus.Width + incidentapparaat.Width) / 3))
    End Sub

    Private Sub AdminmenuV2_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        'resizen
        Opties_Menu_Header.Location = New Point((Me.Size.Width / 2 - (Opties_Menu_Header.Size.Width / 2)), Opties_Menu_Header.Location.Y)
        Klanten_Menu_Header.Location = New Point((Me.Size.Width / 2 - (Klanten_Menu_Header.Size.Width / 2)), Klanten_Menu_Header.Location.Y)
        'Klanten_Menu_Box.Location = New Point((Me.Size.Width / 2 - (Klanten_Menu_Box.Size.Width / 2)), Klanten_Menu_Box.Location.Y)
        KlantenGroupbox.Location = New Point((Me.Size.Width / 2 - (KlantenGroupbox.Size.Width / 2)), KlantenGroupbox.Location.Y)
        WeergaveGroupbox.Location = New Point((Me.Size.Width / 2 - (WeergaveGroupbox.Size.Width / 2)), (Opties_Menu_Header.Location.Y + Opties_Menu_Header.Height + 1))
        Gebruikers_Menu_header.Location = New Point((Me.Size.Width / 3 - (GebruikersGroupbox.Size.Width)) + (GebruikersGroupbox.Size.Width / 2) - (Gebruikers_Menu_header.Size.Width / 2), Gebruikers_Menu_header.Location.Y)
        GebruikersGroupbox.Location = New Point((Me.Size.Width / 3 - (GebruikersGroupbox.Size.Width)), GebruikersGroupbox.Location.Y)
        IncidentenGroupbox.Location = New Point((Me.Size.Width - (Me.Size.Width / 3)), IncidentenGroupbox.Location.Y)
        Incidenten_Menu_Header.Location = New Point((Me.Size.Width - (Me.Size.Width / 3)) + (IncidentenGroupbox.Size.Width / 2) - (Incidenten_Menu_Header.Size.Width / 2), Incidenten_Menu_Header.Location.Y)
        RefreshPictureBox.Location = New Point(IncidentenListView.Location.X + (IncidentenListView.Width - RefreshPictureBox.Width), WeergaveGroupbox.Location.Y)
        AanpassenGroupbox.Location = New Point(AanpassenGroupbox.Location.X, (GebruikersListView.Location.Y + GebruikersListView.Size.Height))
    End Sub


    'Private Sub Uitloggen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Uitloggen_PB.Click, Uitloggen_Label.Click
    '    My.Settings.localuserid = Nothing
    '    My.Settings.localuserlevel = Nothing
    '    My.Settings.localusername = Nothing
    '    My.Settings.localuserovnummer = Nothing
    '    Application.Restart()
    '    'lekker simpel en effectief.
    'End Sub

    'Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Afsluiten_PB.Click, Afsluiten_Label.Click
    '    My.Settings.localuserid = Nothing
    '    My.Settings.localuserlevel = Nothing
    '    My.Settings.localusername = Nothing
    '    My.Settings.localuserovnummer = Nothing
    '    End
    'End Sub

    Private Sub GebruikerMaken_PB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GebruikerMaken_PB.Click, GebruikerMaken_Label.Click
        Bewerkgebruiker.weergeefGebruiker("", True)
    End Sub

    Private Sub GebruikerBewerken_PB_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GebruikerBewerken_PB.Click, GebruikerBewerken_Label.Click
        Opties_Menu_Header.Text = "Gebruikers"
        refreshCurrentList()
    End Sub

    Private Sub KlantMaken_PB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KlantMaken_PB.Click, KlantMaken_Label.Click
        Bewerkklant.weergeefKlant("", True)
    End Sub

    Private Sub KlantBewerken_PB_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KlantBewerken_PB.Click, KlantBewerken_Label.Click
        Opties_Menu_Header.Text = "Klanten"
        refreshCurrentList()
    End Sub

    Private Sub IncidentBewerken_PB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IncidentBewerken_PB.Click, IncidentBewerken_Label.Click
        Opties_Menu_Header.Text = "Incidenten"
        refreshCurrentList()
    End Sub

    Private Sub Weergave_CB_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Weergave_CB.SelectedIndexChanged
        IncidentenListView.Items.Clear()
        beschrijvingen.Clear()
        If Weergave_CB.SelectedIndex = 0 Then 'alle
            For Each row As DataRow In incidents.IncidentsDataSet.Tables("Table").Rows()
                IncidentenListView.Items.Add(row.Item("id")).ToString()
                IncidentenListView.Items(IncidentenListView.Items.Count - 1).SubItems.Add(row.Item("apparaat")).ToString()
                IncidentenListView.Items(IncidentenListView.Items.Count - 1).SubItems.Add(row.Item("ovnummer")).ToString()
                IncidentenListView.Items(IncidentenListView.Items.Count - 1).SubItems.Add(row.Item("categorie")).ToString()
                IncidentenListView.Items(IncidentenListView.Items.Count - 1).SubItems.Add(row.Item("status")).ToString()
                IncidentenListView.Items(IncidentenListView.Items.Count - 1).SubItems.Add(row.Item("behandelaar")).ToString()
                beschrijvingen.Add(row.Item("beschrijving").ToString())
            Next
        ElseIf Not Weergave_CB.SelectedIndex = 0 Then 'The text saved into the database must match the text into the combobox!!
            For Each row As DataRow In incidents.IncidentsDataSet.Tables("Table").Rows()
                If row.Item("status").ToString() = Weergave_CB.Items.Item(Weergave_CB.SelectedIndex).ToString Then
                    IncidentenListView.Items.Add(row.Item("id")).ToString()
                    IncidentenListView.Items(IncidentenListView.Items.Count - 1).SubItems.Add(row.Item("apparaat")).ToString()
                    IncidentenListView.Items(IncidentenListView.Items.Count - 1).SubItems.Add(row.Item("ovnummer")).ToString()
                    IncidentenListView.Items(IncidentenListView.Items.Count - 1).SubItems.Add(row.Item("categorie")).ToString()
                    IncidentenListView.Items(IncidentenListView.Items.Count - 1).SubItems.Add(row.Item("status")).ToString()
                    IncidentenListView.Items(IncidentenListView.Items.Count - 1).SubItems.Add(row.Item("behandelaar")).ToString()
                    beschrijvingen.Add(row.Item("beschrijving").ToString())
                End If
            Next
        End If
    End Sub

    Private Sub RefreshPictureBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RefreshPictureBox.Click
        refreshCurrentList()
    End Sub

    Public Function refreshCurrentList()
        If Opties_Menu_Header.Text.ToLower() = "incidenten" Then
            IncidentenListView.Items.Clear()
            beschrijvingen.Clear()
            GebruikersListView.Hide()
            KlantenListView.Hide()
            IncidentenListView.Show()
            Weergave_CB.Show()
            weergavezoekenLabel.Text = "Weergave:"
            ZoekenTextBox.Hide()
            If incidents.LoadAllFromDB() = "True" Then
                If Weergave_CB.SelectedIndex = 0 Then 'alle
                    For Each row As DataRow In incidents.IncidentsDataSet.Tables("Table").Rows()
                        IncidentenListView.Items.Add(row.Item("id")).ToString()
                        IncidentenListView.Items(IncidentenListView.Items.Count - 1).SubItems.Add(row.Item("apparaat")).ToString()
                        IncidentenListView.Items(IncidentenListView.Items.Count - 1).SubItems.Add(row.Item("ovnummer")).ToString()
                        IncidentenListView.Items(IncidentenListView.Items.Count - 1).SubItems.Add(row.Item("categorie")).ToString()
                        IncidentenListView.Items(IncidentenListView.Items.Count - 1).SubItems.Add(row.Item("status")).ToString()
                        IncidentenListView.Items(IncidentenListView.Items.Count - 1).SubItems.Add(row.Item("behandelaar")).ToString()
                        beschrijvingen.Add(row.Item("beschrijving").ToString())
                    Next
                ElseIf Not Weergave_CB.SelectedIndex = 0 Then 'The text saved into the database must match the text into the combobox!!
                    For Each row As DataRow In incidents.IncidentsDataSet.Tables("Table").Rows()
                        If row.Item("status").ToString() = Weergave_CB.Items.Item(Weergave_CB.SelectedIndex).ToString Then
                            IncidentenListView.Items.Add(row.Item("id")).ToString()
                            IncidentenListView.Items(IncidentenListView.Items.Count - 1).SubItems.Add(row.Item("apparaat")).ToString()
                            IncidentenListView.Items(IncidentenListView.Items.Count - 1).SubItems.Add(row.Item("ovnummer")).ToString()
                            IncidentenListView.Items(IncidentenListView.Items.Count - 1).SubItems.Add(row.Item("categorie")).ToString()
                            IncidentenListView.Items(IncidentenListView.Items.Count - 1).SubItems.Add(row.Item("status")).ToString()
                            IncidentenListView.Items(IncidentenListView.Items.Count - 1).SubItems.Add(row.Item("behandelaar")).ToString()
                            beschrijvingen.Add(row.Item("beschrijving").ToString())
                        End If
                    Next
                End If
            End If
        ElseIf Opties_Menu_Header.Text.ToLower() = "klanten" Then
            KlantenListView.Show()
            Weergave_CB.Hide()
            ZoekenTextBox.Show()
            weergavezoekenLabel.Text = "Zoeken:"
            GebruikersListView.Hide()
            IncidentenListView.Hide()
            KlantenListView.Items.Clear()
            If customers.LoadAllFromDB() = "True" Then
                For Each row As DataRow In customers.KlantenDataSet.Tables("Table").Rows()
                    KlantenListView.Items.Add(row.Item("id")).ToString()
                    KlantenListView.Items(KlantenListView.Items.Count - 1).SubItems.Add(row.Item("voorletter")).ToString()
                    KlantenListView.Items(KlantenListView.Items.Count - 1).SubItems.Add(row.Item("achternaam")).ToString()
                    KlantenListView.Items(KlantenListView.Items.Count - 1).SubItems.Add(row.Item("ovnummer")).ToString()
                    KlantenListView.Items(KlantenListView.Items.Count - 1).SubItems.Add(row.Item("email")).ToString()
                    KlantenListView.Items(KlantenListView.Items.Count - 1).SubItems.Add(row.Item("telefoon")).ToString()
                Next
            End If
        ElseIf Opties_Menu_Header.Text.ToLower() = "gebruikers" Then
            GebruikersListView.Show()
            KlantenListView.Hide()
            IncidentenListView.Hide()
            Weergave_CB.Hide()
            weergavezoekenLabel.Text = "Zoeken:"
            ZoekenTextBox.Text = ""
            ZoekenTextBox.Show()
            GebruikersListView.Items.Clear()
            If users.LoadAllFromDB() = "True" Then
                For Each row As DataRow In users.UsersDataSet.Tables("Table").Rows()
                    GebruikersListView.Items.Add(row.Item("uid")).ToString()
                    GebruikersListView.Items(GebruikersListView.Items.Count - 1).SubItems.Add(row.Item("name")).ToString()
                    GebruikersListView.Items(GebruikersListView.Items.Count - 1).SubItems.Add(row.Item("klas")).ToString()
                    GebruikersListView.Items(GebruikersListView.Items.Count - 1).SubItems.Add(row.Item("ovnummer")).ToString()
                    GebruikersListView.Items(GebruikersListView.Items.Count - 1).SubItems.Add(row.Item("level")).ToString()
                    If row.Item("disabled").ToString() = "True" Then
                        GebruikersListView.Items(GebruikersListView.Items.Count - 1).SubItems.Add("Ja")
                    Else
                        GebruikersListView.Items(GebruikersListView.Items.Count - 1).SubItems.Add("Nee")
                    End If

                Next
            End If
        End If
        Return True
    End Function

    Private Sub updateTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles updateTimer.Tick
        refreshCurrentList()
    End Sub

    Private Sub ZoekenTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ZoekenTextBox.TextChanged
        If Opties_Menu_Header.Text.ToLower = "gebruikers" Then
            GebruikersListView.Items.Clear()

            Dim counter As Integer = 0
            For Each row As DataRow In users.UsersDataSet.Tables("Table").Rows()
                'first check the klas
                Dim strArr() As String
                strArr = row.Item("klas").ToString.ToLower().Split(",")
                For count = 0 To strArr.Length - 1
                    If strArr(count) = ZoekenTextBox.Text Then
                        counter = +1
                        GebruikersListView.Items.Add(row.Item("uid")).ToString()
                        GebruikersListView.Items(GebruikersListView.Items.Count - 1).SubItems.Add(row.Item("name")).ToString()
                        GebruikersListView.Items(GebruikersListView.Items.Count - 1).SubItems.Add(row.Item("klas")).ToString()
                        GebruikersListView.Items(GebruikersListView.Items.Count - 1).SubItems.Add(row.Item("ovnummer")).ToString()
                        GebruikersListView.Items(GebruikersListView.Items.Count - 1).SubItems.Add(row.Item("level")).ToString()
                        If row.Item("disabled").ToString() = "True" Then
                            GebruikersListView.Items(GebruikersListView.Items.Count - 1).SubItems.Add("Ja")
                        Else
                            GebruikersListView.Items(GebruikersListView.Items.Count - 1).SubItems.Add("Nee")
                        End If
                    End If
                Next
            Next
            If counter = 0 Then
                For Each row As DataRow In users.UsersDataSet.Tables("Table").Rows()
                    If row.Item("name").ToString.ToLower().Contains(ZoekenTextBox.Text.ToLower()) Or row.Item("ovnummer").ToString.ToLower().Contains(ZoekenTextBox.Text.ToLower()) Then
                        GebruikersListView.Items.Add(row.Item("uid")).ToString()
                        GebruikersListView.Items(GebruikersListView.Items.Count - 1).SubItems.Add(row.Item("name")).ToString()
                        GebruikersListView.Items(GebruikersListView.Items.Count - 1).SubItems.Add(row.Item("klas")).ToString()
                        GebruikersListView.Items(GebruikersListView.Items.Count - 1).SubItems.Add(row.Item("ovnummer")).ToString()
                        GebruikersListView.Items(GebruikersListView.Items.Count - 1).SubItems.Add(row.Item("level")).ToString()
                        If row.Item("disabled").ToString() = "True" Then
                            GebruikersListView.Items(GebruikersListView.Items.Count - 1).SubItems.Add("Ja")
                        Else
                            GebruikersListView.Items(GebruikersListView.Items.Count - 1).SubItems.Add("Nee")
                        End If
                    End If
                Next
            Else
                'no results found                    
            End If

        ElseIf Opties_Menu_Header.Text.ToLower = "klanten" Then
            KlantenListView.Items.Clear()

            For Each row As DataRow In customers.KlantenDataSet.Tables("Table").Rows()
                If row.Item("achternaam").ToString.ToLower().Contains(ZoekenTextBox.Text.ToLower()) Or row.Item("ovnummer").ToString.ToLower().Contains(ZoekenTextBox.Text.ToLower()) Or row.Item("email").ToString.ToLower().Contains(ZoekenTextBox.Text.ToLower()) Then
                    KlantenListView.Items.Add(row.Item("id")).ToString()
                    KlantenListView.Items(KlantenListView.Items.Count - 1).SubItems.Add(row.Item("voorletter")).ToString()
                    KlantenListView.Items(KlantenListView.Items.Count - 1).SubItems.Add(row.Item("achternaam")).ToString()
                    KlantenListView.Items(KlantenListView.Items.Count - 1).SubItems.Add(row.Item("ovnummer")).ToString()
                    KlantenListView.Items(KlantenListView.Items.Count - 1).SubItems.Add(row.Item("email")).ToString()
                    KlantenListView.Items(KlantenListView.Items.Count - 1).SubItems.Add(row.Item("telefoon")).ToString()
                End If
            Next
        End If
    End Sub


    Private Sub ItemVerwijderen_Label_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ItemVerwijderen_Label.Click
        
        Dim msg As MsgBoxResult
        If Opties_Menu_Header.Text.ToLower = "gebruikers" Then
            If GebruikersListView.SelectedItems.Count = 0 Then
                Exit Sub
            End If
            msg = MsgBox("Weet u zeker dat u " + GebruikersListView.SelectedItems.Count.ToString + " " + Opties_Menu_Header.Text.ToLower + " wilt verwijderen?", MsgBoxStyle.YesNo, "Verwijderen")
        ElseIf Opties_Menu_Header.Text.ToLower = "klanten" Then
            If KlantenListView.SelectedItems.Count = 0 Then
                Exit Sub
            End If
            msg = MsgBox("Weet u zeker dat u " + KlantenListView.SelectedItems.Count.ToString + " " + Opties_Menu_Header.Text.ToLower + " wilt verwijderen? De gekoppelde incidenten worden ook verwijderd!", MsgBoxStyle.YesNo, "Verwijderen")
        ElseIf Opties_Menu_Header.Text.ToLower = "incidenten" Then
            If IncidentenListView.SelectedItems.Count = 0 Then
                Exit Sub
            End If
            msg = MsgBox("Weet u zeker dat u " + IncidentenListView.SelectedItems.Count.ToString + " " + Opties_Menu_Header.Text.ToLower + " wilt verwijderen?", MsgBoxStyle.YesNo, "Verwijderen")
        End If

        If msg = MsgBoxResult.Yes Then
            If Opties_Menu_Header.Text.ToLower = "gebruikers" Then
                For count As Integer = 0 To (GebruikersListView.SelectedItems.Count - 1)
                    users.DeleteFromDB(GebruikersListView.SelectedItems.Item(count).SubItems.Item(3).Text.ToString)
                Next
            ElseIf Opties_Menu_Header.Text.ToLower = "klanten" Then
                For count As Integer = 0 To (KlantenListView.SelectedItems.Count - 1)
                    Dim result As String = customers.DeleteFromDB(KlantenListView.SelectedItems.Item(count).SubItems.Item(0).Text.ToString, True)
                    If Not result = "True" Then
                        MsgBox("er is iets fout gegaan bij het verwijderen van de klanten: " + result + vbNewLine + "De klant " + KlantenListView.SelectedItems.Item(count).SubItems.Item(1).Text.ToString + " " + KlantenListView.SelectedItems.Item(count).SubItems.Item(2).Text.ToString + " is niet verwijderd.")
                    End If
                Next
            ElseIf Opties_Menu_Header.Text.ToLower = "incidenten" Then
                For count As Integer = 0 To (IncidentenListView.SelectedItems.Count - 1)
                    incidents.DeleteFromDB(IncidentenListView.SelectedItems.Item(count).SubItems.Item(0).Text.ToString)
                Next
            End If
            refreshCurrentList()
        End If
    End Sub

    Private Sub ItemBewerken_Label_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ItemBewerken_Label.Click
        If Opties_Menu_Header.Text.ToLower = "gebruikers" Then

            If GebruikersListView.SelectedItems.Count = 0 Then
                Exit Sub
            End If

            Dim endcount As Integer = 4
            If GebruikersListView.SelectedItems.Count - 1 < 4 Then
                endcount = GebruikersListView.SelectedItems.Count - 1
            End If

            For count As Integer = 0 To endcount 'max 5.
                Dim window As New Bewerkgebruiker
                window.weergeefGebruiker(GebruikersListView.SelectedItems.Item(count).SubItems.Item(3).Text.ToString)
            Next


        ElseIf Opties_Menu_Header.Text.ToLower = "klanten" Then

            If KlantenListView.SelectedItems.Count = 0 Then
                Exit Sub
            End If

            Dim endcount As Integer = 4
            If KlantenListView.SelectedItems.Count - 1 < 4 Then
                endcount = KlantenListView.SelectedItems.Count - 1
            End If

            For count As Integer = 0 To endcount 'max 5.
                Dim window As New Bewerkklant
                window.weergeefKlant(KlantenListView.SelectedItems.Item(count).SubItems.Item(0).Text.ToString)
            Next


        ElseIf Opties_Menu_Header.Text.ToLower = "incidenten" Then

            If IncidentenListView.SelectedItems.Count = 0 Then
                Exit Sub
            End If

            Dim endcount As Integer = 4
            If IncidentenListView.SelectedItems.Count - 1 < 4 Then
                endcount = IncidentenListView.SelectedItems.Count - 1
            End If

            For count As Integer = 0 To endcount 'max 5.
                Dim window As New Bewerkincident
                window.weergeefIncident(IncidentenListView.SelectedItems.Item(count).SubItems.Item(0).Text.ToString)
            Next


        End If
    End Sub
End Class




Public Class groupboxcolor
    Inherits GroupBox

    'Property to give you control over the color
    Private mBorderColor As Color = Color.FromArgb(64, 64, 64)
    Public Property BorderColor() As Color
        Get
            Return mBorderColor
        End Get
        Set(ByVal value As Color)
            mBorderColor = value
        End Set
    End Property

    'This Draws the line
    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        Dim tSize As Size = TextRenderer.MeasureText(Me.Text, Me.Font)
        Dim borderRect As Rectangle = e.ClipRectangle
        borderRect.Y = (borderRect.Y _
                    + (tSize.Height / 2))
        borderRect.Height = (borderRect.Height _
                    - (tSize.Height / 2))
        ControlPaint.DrawBorder(e.Graphics, borderRect, Me.borderColor, ButtonBorderStyle.Solid)
        Dim textRect As Rectangle = e.ClipRectangle
        textRect.X = (textRect.X + 6)
        textRect.Width = tSize.Width
        textRect.Height = tSize.Height
        e.Graphics.FillRectangle(New SolidBrush(Me.BackColor), textRect)
        e.Graphics.DrawString(Me.Text, Me.Font, New SolidBrush(Me.ForeColor), textRect)
    End Sub
End Class
